
public class e044 {
    public static void main(String[] args) {
        long sTime = System.currentTimeMillis();
        int[] pent = new int[10000];
        loop:
        for (int n = 1; n < 10000; n++) {
            pent[n] = pentagonal(n);
            for (int j = 1; j < n; j++) {
                int jSk = pent[n] - pent[j];
                int jAk = pent[n] + jSk;
                if (isPentagonal(jSk) && isPentagonal(jAk)) {
                    System.out.println(pent[j]);
                    break loop;
                }
            }
        }
        long fTime = System.currentTimeMillis();
        System.out.println("Time: " + (fTime - sTime) + "ms");
    }
    
    static boolean isPentagonal(int i) {
        double n = (Math.sqrt(24 * i + 1) + 1) / 6;
        return (n == (long)n);
    }

    static int pentagonal(int i) {
        return i * (3 * i - 1) / 2;
    }
}